cmake_minimum_required(VERSION 3.16)
project(RemoteMaster LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置Visual Studio启动项目
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT RemoteMaster)

# 查找Qt6包
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Gui Network OpenGL)

# 添加子目录
add_subdirectory(core)
add_subdirectory(vnc)
add_subdirectory(rdp)
add_subdirectory(render)
add_subdirectory(ui)
add_subdirectory(service)

# 添加可执行文件
add_executable(RemoteMaster WIN32
    src/main.cpp
)

# 设置Visual Studio文件夹结构
set_property(TARGET RemoteMaster PROPERTY FOLDER "Applications")

# 链接Qt库
target_link_libraries(RemoteMaster 
    Qt6::Core 
    Qt6::Widgets 
    Qt6::Gui 
    Qt6::Network
    Qt6::OpenGL
    core
    vnc
    rdp
    render
    ui
    service
)

# 包含目录
target_include_directories(RemoteMaster PRIVATE src)

# 添加资源
set(RESOURCES_RESOURCES_RCC ${CMAKE_CURRENT_SOURCE_DIR}/resources/resources.qrc)
qt6_add_resources(RESOURCES ${RESOURCES_RESOURCES_RCC})
target_sources(RemoteMaster PRIVATE ${RESOURCES} ${RESOURCES_RESOURCES_RCC})

# 设置资源文件的Visual Studio过滤器
source_group("Resource Files" FILES ${RESOURCES_RESOURCES_RCC})

# 编译器特定选项
if(WIN32)
    # Windows特定设置
    target_link_libraries(RemoteMaster Qt6::WinExtras)
    
    # Windows图标和元信息
    set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/resources/icon.rc")
    if(EXISTS ${APP_ICON_RESOURCE_WINDOWS})
        target_sources(RemoteMaster PRIVATE ${APP_ICON_RESOURCE_WINDOWS})
        source_group("Resource Files" FILES ${APP_ICON_RESOURCE_WINDOWS})
    endif()
    
    # 设置可执行文件属性
    set_target_properties(RemoteMaster PROPERTIES
        WIN32_EXECUTABLE ON
        LINK_FLAGS "/SUBSYSTEM:WINDOWS"
    )
endif()

# 启用调试构建中的调试输出
target_compile_definitions(RemoteMaster PRIVATE 
    $<$<CONFIG:Debug>:DEBUG_OUTPUT>
)

# 设置输出目录
set(OUTPUT_DIR ${CMAKE_BINARY_DIR}/$<CONFIGURATION>)
set_target_properties(RemoteMaster PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR}
    LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR}
    ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIR}
)

# 设置Visual Studio调试工作目录
set_property(TARGET RemoteMaster PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${OUTPUT_DIR}")